package com.situ.blog.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.situ.blog.mapper.BlogMapper;
import com.situ.blog.pojo.entity.Blog;
import com.situ.blog.pojo.vo.BlogExcelVO;
import org.springframework.beans.BeanUtils;

public class BlogExcelListener extends AnalysisEventListener<BlogExcelVO> {
    private BlogMapper blogMapper;

    public BlogExcelListener(BlogMapper blogMapper) {
        this.blogMapper = blogMapper;
    }


    @Override
    public void invoke(BlogExcelVO blogExcelVO, AnalysisContext analysisContext) {
        System.out.println("BlogExcelListener.invoke");
        Blog blog = new Blog();
        BeanUtils.copyProperties(blogExcelVO, blog);
        blog.setId(null);
        blogMapper.insert(blog);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
